package com.chenfan.mcn.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @author:   tangwei
 * Date:     2021/3/4 15:02
 * Description: 红人账户打款类型
 */
@AllArgsConstructor
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum StudioPaymentEnum {

    /**
     * 红人账户打款类型
     */

    COMPANY(1, "公司"),
    PERSONAL(2, "个人"),
    STUDIO(3, "工作室"),

    ;
    @Getter
    private Integer type;

    @Getter
    private String desc;

    /**
     * 根据code获取 枚举
     * @param type
     * @return
     */
    public static StudioPaymentEnum toEnum(Integer type) {
        if(Objects.isNull(type)) {
            return null;
        }
        StudioPaymentEnum studioPaymentEnum = null;
        for (StudioPaymentEnum item : StudioPaymentEnum.values()) {
            if (item.getType() == type.intValue()) {
                studioPaymentEnum = item;
                break;
            }
        }
        return studioPaymentEnum;
    }


    /**
     * 获取状态名称
     * @param type
     * @return
     */
    public static String getDesc(Integer type) {
        StudioPaymentEnum studioPaymentEnum = StudioPaymentEnum.toEnum(type);
        return studioPaymentEnum != null ? studioPaymentEnum.desc : null;
    }

    /**
     * 获取打款类型枚举
     * @param desc
     * @return
     */
    public static Integer getType(String desc) {
        for (StudioPaymentEnum item : StudioPaymentEnum.values()) {
            if (item.getDesc().equals(desc)) {
                return item.getType();
            }
        }
        return null;
    }

    /**
     * 是公司
     * @param type
     * @return
     */
    public static boolean isCompany(Integer type) {
        return StudioPaymentEnum.COMPANY.type.equals(type);
    }
}